import java.util.Random;

public class ThreadDemo {


   /* public static class MyThread extends Thread
    {
        @Override
        public void run() {
            Random random = new Random();
            while(true)
            {
                //随机打印一个线程
                System.out.println(Thread.currentThread().getName());
                try {
                    Thread.sleep(random.nextInt(10));
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }*/
    public static void main(String[] args)
    {
      /*  MyThread t1 = new MyThread();
        t1.start();*/
     /*   Thread thread  = new Thread(new Runnable()
        {
           @Override
           public void run()
           {
               System.out.print("通过内部类重写Runnable子类的run方法创建的线程");
           }
        });*/
   /*    Thread thread  = new Thread()
        {
           @Override
           public void run()
           {
               System.out.print("通过内部类重写Thread子类的run方法创建的线程");
           }
        };
        thread.start();*/
        Thread t1 = new Thread();
        Thread t2 = new Thread(new MyRunnable());
        Thread t3 = new Thread("线程3");
        Thread t4 = new Thread(new MyRunnable(),"线程4");
        System.out.println(t1.getId());
        System.out.println(t2.getId());
        System.out.println(t3.getId());
        System.out.println(t4.getId());
    }
}
